<script type="text/javascript">
		
		/* Global variables used by the GPS Visualizer functions (1194532800): */
		gv_options = new Array(); gv_options = {
			// important variable names:
			map:'gmap', map_div:'gmap_div', marker_array:'wpts', track_info_array:'trk_info', // probably 'gmap','gmap_div','wpts','trk_info'
			
			// basic map parameters:
			full_screen:true,               // should the map fill the entire page (or frame)?
			center:[<?php echo $center->lat;?>,<?php echo $center->lon;?>],    // latitude,longitude - be sure to keep the square brackets
			zoom:12,                         // higher number means closer view; at 600px wide, 7 = width of New Mexico, 12 = width of San Francisco
			map_type:'G_HYBRID_MAP',        // Popular choices are 'G_NORMAL_MAP', 'G_SATELLITE_MAP', 'G_HYBRID_MAP', 'USGS_TOPO_TILES'
			map_opacity:1,                  // number from 0 to 1
			doubleclick_zoom:false,         // true or false; false means double-clicking simply re-centers the map
			mousewheel_zoom:true,          // enables zooming with mouse wheel; value of 'reverse' makes down=in and up=out
			
			// widgets on the map:
			map_type_control:{ // style: 'menu', 'list', 'none', or 'google'; filter: when map loads, are irrelevant maps ignored?; excluded: list of map types that will never show in the list, e.g., ['USGS_TOPO_TILES','USGS_AERIAL_TILES','NRCAN_TOPO_TILES','NRCAN_TOPO_NAMES_TILES','LANDSAT_TILES','BLUEMARBLE_TILES','DAILY_TERRA_TILES','DAILY_AQUA_TILES']
				style:'menu', filter:true, excluded:[]
			},
			map_opacity_control:false,       // true or false
			zoom_control:'large',           // 'large' or 'small'
			scale_control:true,             // true or false
			center_coordinates:true,        // true or false; show a "center coordinates" box and crosshair?
			crosshair_hidden:false,         // true or false; when map first loads, is the crosshair hidden?
			legend_options:{                // position: [Google anchor, x, y]; id: id of a DIV tag that holds the legend (other associated DIVs -- e.g., _handle, _table, -container -- must be similarly named)
				legend:false, id:'gv_legend', position:['G_ANCHOR_BOTTOM_LEFT',4,60], draggable:true
			},
			
			// marker-related options:
			default_marker:{ color:'red',icon:'googlemini' }, // icon can be a URL, but be sure to also include size:[w,h]
			icon_directory:'http://maps.gpsvisualizer.com/google_maps/icons/', // don't change this unless you really know what you're doing
			marker_link_target:'_blank',    // the name of the window or frame into which markers' URLs will load
			label_offset:[0,0],             // if points have labels, you can shift ALL of them by [x,y] pixels (you can also set the points' label offsets individually)
			hide_labels:false,              // set this to true if you want the "permanent" labels to be hidden at first
			driving_directions:false,       // put a small "driving directions" form in each marker's pop-up window? (override with dd:true or dd:false in the marker's options)
			
			// track-related options:
			filter_tracks:false,            // should out-of-the-viewport tracks be hidden?
			tracklist_options:{             // position: [Google anchor, x, y]; id: id of a DIV tag that holds the track list (other associated DIVs -- e.g., _handle, _table, -container -- must be similarly named)
				tracklist:true, id:'gv_tracklist', position:['G_ANCHOR_TOP_RIGHT',6,32], draggable:true
			},

			zzz:false // this is just here to prevent possible "hanging comma" JS errors
		};
		
		// Load GPS Visualizer's Google Maps functions (very important!):
		document.writeln('<script src="<?php echo $CFG->wwwroot . "/mercurius/gmaps/functions.js";?>" type="text/javascript"><'+'/'+'script>');
		
		function GV_Map() {
			if (GBrowserIsCompatible()) { 
				gmap = new GMap2(document.getElementById(gv_options['map_div'])); // create map
				GV_Setup_Map(gv_options);
				
				
				trk_info = new Array();
				
				<?php
					
				foreach($data as $trknum => $track) {
					$name = addslashes($track->name);
					$trkdata = $track->data;\
					$lastlat = 0;
					$lastlon = 0;
					$firstlat = 0;
					$firstlon = 0;

					?> 
					// Draw track #1 ("<?php echo $name;?>")
					<?php
					$color = "#E600E6";
					if(count($data) > 1) {
						$color = "#" . rndm_color_code(TRUE);
					}
					
					?>
					trk<?php echo $trknum;?> = new Array(); var trk<?php echo $trknum;?>_color = "<?php echo $color;?>"; var trk<?php echo $trknum;?>_width = 3; var trk<?php echo $trknum;?>_opacity = 0.8;
					// track <?php echo $trknum;?> segment 1:
					var pts1_1 = [
					<?php
						$postfirst = false;
						foreach($trkdata as $row => $sessrow) {
							if($postfirst) {
								echo ", new GLatLng($sessrow->lat,$sessrow->lon)";
							} else {
								echo "new GLatLng($sessrow->lat,$sessrow->lon)";
								$firstlat = $sessrow->lat;
								$firstlon = $sessrow->lon;
								$postfirst = true;
							}
						}
						echo "\n";
					?>
					];
					trk<?php echo $trknum;?>.push (new GPolyline(pts1_1,GV_Color_Name2Hex(trk<?php echo $trknum;?>_color),trk<?php echo $trknum;?>_width,trk<?php echo $trknum;?>_opacity)); gmap.addOverlay(trk<?php echo $trknum;?>[trk<?php echo $trknum;?>.length-1]);
					trk_info['trk<?php echo $trknum;?>'] = { w:<?php echo $lastlon;?>,e:<?php echo $firstlon;?>,s:<?php echo $lastlat;?>,n:<?php echo $firstlat;?> };
					GV_Add_Track_to_Tracklist({bullet:'- ',name:'<?php echo $name;?>',desc:'<?php include($CFG->dirroot . '/mercurius/gmaps/summary.html');?>',color:trk<?php echo $trknum;?>_color,map_name:'gmap',id:'trk<?php echo $trknum;?>'});
				<?php
				}
				?>

				
				var bounds = new GLatLngBounds;
  				for (var i=0; i<pts1_1.length; i++) {
    				bounds.extend(pts1_1[i]);
  				}
  				
  				gv_options['center'] = [bounds.getCenter().lat(),bounds.getCenter().lng()];
  				gv_options['zoom'] = gmap.getBoundsZoomLevel(bounds) + 1;
  				GV_Setup_Map(gv_options);
  				wpts = new Array();
				GV_Finish_Map(gv_options);
				

			} else {
				document.getElementById('gmap_div').style.backgroundColor = '#DDDDDD';
				document.getElementById('gmap_div').innerHTML = 'Sorry, your Google Map cannot be displayed.';
			}
		}

		</script>